// pages/member/address.js
var util = require("../../../utils/util.js");

//获取应用实例
const app = getApp()
var i;
Page({

    /**
     * 页面的初始数据
     */
    data: {
      address: '',
      name: '',
      identity: '',
      isSubmit: false,
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

      let that = this;
      var pages = getCurrentPages();
      var prevPage = pages[pages.length - 2];
      // console.log("---------", prevPage.data);

      that.setData({
        address: prevPage.data.user.address,
        identity: prevPage.data.user.identity,
        name: prevPage.data.user.name
      })


    },

    getInputValue(e) {
      let that = this;
      let value = e.detail.value;
      let type = e.currentTarget.dataset.type

      that.setData({
        [type]: value,
      })

    },

    onSubmit(e) {
      let that = this;
      let name = that.data.name;
      let address = that.data.address;
      let identity = that.data.identity;
      if(name.trim() == '' || identity.trim() == '' || address.trim() == '') {
        app.tip('请填写完整');
        return ;
      }
      that.setData({
        isSubmit: true,
      })
      
      app.httpPost('member/personal/update', {
        'name': name,
        'address': address,
        'identity': identity,
      }, json => {
        wx.navigateBack({
          delta: -1,
        })
        if(json.data.error != 0) {
          app.tip(json.data.message)
        }else {
          wx.navigateBack({
            delta: -1,
          })
          app.tip("成功！")
        }
     
      })


    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },


})